﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RCloud.Data.List
{
    public class RatingHistory : Doo.DataClass.ListClass<REntities, UserRatingHistory>
    {
        /// <summary>
        /// 查询结束时间
        /// </summary>
        public int TimeStampEnd { get; set; }

        /// <summary>
        /// 查询开始时间
        /// </summary>
        public int TimeStampStart { get; set; }

        public override IOrderedQueryable<UserRatingHistory> GetQuery(REntities container)
        {
            var query_init = container.UserRatingHistory.AsQueryable();

            if (TimeStampStart > 0) query_init = query_init.Where(r => r.TimeStamp >= TimeStampStart);
            if (TimeStampEnd > 0) query_init = query_init.Where(r => r.TimeStamp <= TimeStampEnd);

            var query = from rh in query_init
                        orderby rh.TimeStamp
                        select rh;
            return query;
        }
    }

    public class RatingHistoryLiteClass : Doo.DataClass.ListClass<REntities, UserRatingHistoryLite>
    {
        /// <summary>
        /// 查询结束时间
        /// </summary>
        public int TimeStampEnd { get; set; }

        /// <summary>
        /// 查询开始时间
        /// </summary>
        public int TimeStampStart { get; set; }

        /// <summary>
        /// 限定于该MovieID
        /// </summary>
        public int MovieID { get; set; }

        public override IOrderedQueryable<UserRatingHistoryLite> GetQuery(REntities container)
        {
            var query_init = container.UserRatingHistoryLite.AsQueryable();

            if (TimeStampStart > 0) query_init = query_init.Where(r => r.TimeStamp >= TimeStampStart);
            if (TimeStampEnd > 0) query_init = query_init.Where(r => r.TimeStamp <= TimeStampEnd);
            if (MovieID > 0) query_init = query_init.Where(r => r.MovieID == MovieID);

            var query = from rh in query_init
                        orderby rh.TimeStamp
                        select rh;
            return query;
        }
    }

}
